// JavaScript Document
Vue.component('item-comp',{
	template:'<div class="list">\
                    <div class="img"><img :src="item.img"></div>\
                    <template v-if="(item.type != \'自定义\') || item.count>0"> \
						<template v-if="item.count>0">\
                       		<div class="tit">{{item.name}}</div>\
                        	<div class="jj"><span v-on:click="minus">-</span><em>{{item.count}}</em><span v-on:click="add">+</span></div>\
                        	<div class="r">￥{{item.price}}<i v-on:click="deleteItem(item.id)">X</i></div>\
						</template>\
						<template v-if="!item.count||item.count==0">\
							<div class="tit">{{item.type}}</div>\
							<div class="r"><a href="#" v-on:click="changeItem($event)">添加</a></div>\
						</template>\
					</template>\
					<template v-if="item.type == \'自定义\' && (!item.count || item.count ==0)"> \
							<div class="tit">{{item.type}}</div>\
					        <div class="r" id="showbox" style="position:relateve;"><a href="#" class="add" v-on:click="changeItem($event)">&nbsp;</a>\
							<div class="xx-box"><div class="TIOnwr">选择自定义:</div><ul id="onxl"><li class="HoA">灯具</li><li>花艺</li><li>饰品</li><li>挂画</li><li>布艺家纺</li><li>地毯</li><li>摆件</li></ul></div>\
							</div>\
					</template>\
                    </div>',
	props:['item','index'],
	data:function(){
		return {
			defaultInfo:{}
		}
	},
	methods:{
		add:function(){
			this.item.count += 1;	
		},
		minus:function(){
			if(this.item.count > 1){
				this.item.count -= 1;	
			}
		},
		deleteItem:function(id){/*
			delete this.item.id;
			delete this.item.price;
			this.item.count =0;
			delete this.name;*/
			this.item.price = '';
			this.item.count = 0;
			this.name = '';
			this.item.img = this.defaultInfo.img;
			this.item.name = this.defaultInfo.name;
		},
		changeItem:function(event){
			//console.log(this.item.id)
			//vm.init();
			vm.spaceObjectId = this.item.id;
			vm.searchTerm = this.item.name;
			this.defaultInfo = {
				type:this.item.type,
				img:this.item.img,
				name: this.item.name
			}
			this.$emit('changeitem',this.index);
			event.preventDefault();
		}
	}
});